<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>首媒管理平台</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    <!--[if lt IE 8]>
	    <meta http-equiv="refresh" content="0;ie.html" />
	    <![endif]-->
	    <link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=${static_version}" rel="stylesheet">
	    
	    <link href="${ctx}/static/plugins/easyui/themes/metro/easyui.css?v=${static_version}" rel="stylesheet">
    	<link href="${ctx}/static/plugins/easyui/themes/icon.css?v=${static_version}" rel="stylesheet">
	    
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content datatable">
                <form class="form-group" id="sysUser_table_form">	
                	<input type="hidden" name="userType" value="sysUser">
                	<input type="hidden" name="orderBy" value="create_date desc">
                	<div class="row">
                        <div class="col-md-2 col-xs-2 col-sm-2 col-lg-2"><input name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
						<div class="col-md-4 col-xs-4 col-sm-4 col-lg-4">
                            <div class="input-group">
                                <input id="startTime" type="text" class="input-md input-xs form-control" placeholder="开始时间"  name="startTime">
					        	<span class="input-group-addon">至</span>
					        	<input id="endTime" type="text" class="input-md input-xs form-control" placeholder="结束时间"  name="endTime">
                            </div>
					    </div>
					    <div id="table-pull-right" class="pull-right col-md-1 col-sm-2">
							<button onclick="clickInsertGet(this)" type="button" class="btn btn-block btn-outline btn-primary">添加</button>
					    </div>
						<div class="col-md-2 col-xs-2 col-sm-2 col-lg-2">
							<button id="sysUser_table_search"  type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
                    </div>
                </form>
				<table id="sysUser_table" data-action="${ctx}/user/find" data-datatable="true"  class="footable table table-stripped toggle-arrow-tiny">
				  	<thead>
					  	<tr>
					  		<th  data-sort-ignore="true" data-title ="image" data-hide="phone,tablet" data-type="togecallback" data-toge="phone,username"  data-callback="initUserImage">头像</th>
					  		<th  data-sort-ignore="true" data-title ="username" data-toggle="true">登录用户名</th>
					  		<th  data-sort-ignore="true" data-title ="fullname" >姓名</th>
							<th  data-sort-ignore="true" data-title ="gender" data-hide="phone,tablet"  data-type="enum" data-opt='{"1":"男","2":"女"}'>性别</th>
							<th  data-sort-ignore="true" data-title ="roles" data-hide="phone,tablet">拥有角色</th>
							<th  data-sort-ignore="true" data-title ="phone" data-hide="phone,tablet">手机号</th>
							<th  data-sort-ignore="true" data-title ="status" data-hide="phone,tablet" data-type="enum" data-opt='{"0":"启用","1":"禁用"}'>状态</th>
							<th  data-sort-ignore="true" data-title ="createUsername" data-formater="yyyy-MM-dd" data-hide="phone,tablet">创建人</th>
							<th  data-sort-ignore="true" data-title ="createDate" data-hide="phone,tablet" data-type="date" >创建时间</th>
		      		      	<th data-sort-ignore="true"  data-crud="true" data-title='{"uid":"id"}' data-hide="phone">操作
			      			  <div style="display: none;" class="center hidden-phone">
			      			  		<button onclick="clickResetPassword(this)" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-outline btn-warning btn-xs"><i class="fa fa-link"></i>&nbsp;重置密码</button>
			      			  		<button data-type='change' data-toge="status"  data-callback="changeStatusCallback" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-primary btn-xs">启用/禁用</button>
							  		<button data-title="更新" onclick="clickUpdateGet(this)" style="margin-left:3px;margin-top:3px" data-url="${ctx}/user/update"  data-id=":uid" type="button" class="btn btn-info btn-outline btn-xs"><i class="fa fa-pencil"></i>&nbsp;更新</button>
						  		</div> 
		      		      	</th>
					  	</tr>
				  	</thead>
				  	<tbody>
				  	</tbody>
			  	</table>
			  	<div class="row">
			  		<div class="col-md-4 col-xs-4 col-sm-4 col-lg-4" class="pull-left" id="page_left_text"></div>
			  		<div class="col-md-8"  id="page_text"></div>
			  	</div>
			</div>
		</div>
		
	<a id="openNewTag" style="display:none;" class="J_menuItem" data-index="${ctx}/resource/index" href="${ctx}/resource/index"><i class="fa fa-columns"></i> <span class="nav-label">打开资源列表</span></a>	
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	
	<script src="${ctx}/static/plugins/easyui/jquery.easyui.min.js?v=${static_version}"></script>
	
	<script>

		var openNewTag=function(me,id){
			alert("sss");
			$("#openNewTag").attr("href","${ctx}/resource/index?id="+id);
	  		$("#openNewTag").click();	 
		}
		
		var initUserImage=function(cData,cLable,row){
			return '<img alt="image" class="img-circle message-avatar" src="'+cData+'">';
		}
		
		var changeStatusCallback=function(cData,cLable,row){
			if(row["status"]==1){
				return '<button onclick="clickChangeStatus(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;启用</button>';
			}else{
				return '<button onclick="clickChangeStatus(this,1)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;禁用</button>';
			}
		}
		
		var clickChangeStatus=function(me,status){
			var text="确定禁用用户?";
			 if(status===0){
				 text="确定启用用户?";
			 }else if(status===1){
				 text="确定禁用用户?";
			 }
			 $.confirm({
			    text:text,
			    confirmButton: "确定",
			    cancelButton: "取消",
			    confirm: function() {
			    	$.ajax({  
			    		url:'${ctx}/user/update',  
	   					data:{
	   						id:$(me).data("id"),
	   						status:status
	   					},   
						type: 'POST',
   	 					dataType:'json',  
   	 					success:function(response){
   	 						if(response.code==0){
   	 							eModal.close();
   	 							$("#sysUser_table_search").click();
   	 						}else{
   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"改变用户状态错误!"});
   	 						}
   	 					}  
   	 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
		
		var clickResetPassword=function(me){
			$.confirm({
			    text:"确定重置用户密码?",
			    confirmButton: "确定",
			    cancelButton: "取消",
			    confirm: function() {
			    	$.ajax({  
	   	 		    	url:'${ctx}/user/resetPassword',  
	   					data:{
	   						id:$(me).data("id")
	   					},   
						type: 'POST',
   	 					dataType:'json',  
   	 					success:function(response){
   	 						if(response.code==0){
   	 							$.confirm({cancelButton: "关   闭",title: '提示!',content:"重置用户密码成功,重置后密码 123456!"});
   	 							eModal.close();
   	 						}else{
   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content:"修改用户密码错误!"});
   	 						}
   	 					}  
   	 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}
	
		$(document).ready(function() {
			init_page_datatable();
		});
		
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/user/updateGet?id="+$(me).data("id"),
	   	        title:'修改用户',
	   	        loading:true,
	   	        size: eModal.size.sm,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存', style: 'info',   close: false, click:function(){
		   	 			if (!jQuery.checkall(true)) return;
	   	            	if($("#roleIds").val()==null){
 	 						parent.layer.msg('用户角色不能为空！', {icon: 2});
	   	            	}
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/user/update',  
	   	 					data:{
								gender:$("input[name='gender']:checked").val(),
								roleIds:$("#roleIds").val().join(","),
								departmentId:$("#departmentId").combotree("getValue"),							
								fullname:$("#fullname").val(),						
								userType:"sysUser",										
								username:$("#username").val(),	
								phone:$("#phone").val(),
								token:$("#token").val(),	
								id:$("#user-id").val()
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysUser_table_search").click();
	   	 						}else if(response.message==1){
	   	 							$.confirm({cancelButton: "关   闭",title: '提示!',content:'用户名已存在！'});
	   	 						}else if(response.message==2){
	   	 							$.confirm({cancelButton: "关   闭",title: '提示!',content:'手机号已被注册！'});
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
			return false;
		}
		
		var clickInsertGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/user/insertGet",
	   	        title:'添加用户',
	   	        loading:true,
	   	        size: eModal.size.sm,
	   	        buttons: [
	   	            {text: '保存', style: 'info', close: false, click:function(){
	   	            	if (!jQuery.checkall(true)) return;
	   	            	var roleIds_=$("#roleIds").val().join(",");
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/user/add',  
	   	 					data:{
	   	 						gender:$("input[name='gender']:checked").val(),	
	   	 						departmentId:$("#departmentId").combotree("getValue"),	
								roleIds:roleIds_,	
								password:$("#password").val()==""?"123456":$("#password").val(),							
								fullname:$("#fullname").val(),		
								phone:$("#phone").val(),	
								token:$("#token").val(),	
								username:$("#username").val()						
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#sysUser_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示!',content: (me).data("title")+"错误!"||"保存数据错误!"});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
			return false;
		}
		
		$(function(){
			jQuery.searchFormInit();
			
			jQuery.smallTabMenuInit();
		});
	</script>
	
	</body>
</html>